// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package base

import (
	"strings"
)

// Level
// is a type name of log level.
type Level string

// Level enum.

const (
	LevelDebug Level = "DEBUG"
	LevelInfo  Level = "INFO"
	LevelWarn  Level = "WARN"
	LevelError Level = "ERROR"
	LevelFatal Level = "FATAL"

	defaultLevel = LevelInfo
)

// Generator
// generates a valid level.
func (o Level) Generator() Level {
	l := Level(strings.ToUpper(strings.TrimSpace(o.String())))
	switch l {
	case LevelDebug, LevelInfo, LevelWarn, LevelError, LevelFatal:
		return l
	default:
		return defaultLevel
	}
}

// String
// returns the level name.
func (o Level) String() string {
	return string(o)
}

// State compared.

func (o Level) IsDebug() bool { return o == LevelDebug }
func (o Level) IsError() bool { return o == LevelError }
func (o Level) IsFatal() bool { return o == LevelFatal }
func (o Level) IsInfo() bool  { return o == LevelInfo }
func (o Level) IsWarn() bool  { return o == LevelWarn }
